package com.pond.pond.controller;

import com.pond.common.core.web.controller.BaseController;
import com.pond.common.core.web.domain.AjaxResult;
import com.pond.common.security.annotation.RequiresPermissions;
import com.pond.pond.service.IFishingTechniqueStatsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 钓技学堂统计分析Controller
 * 
 * @author pond
 * @date 2024-01-15
 */
@RestController
@RequestMapping("/fishing/stats")
public class FishingTechniqueStatsController extends BaseController
{
    @Autowired
    private IFishingTechniqueStatsService fishingTechniqueStatsService;

    /**
     * 获取统计概览数据
     */
    @RequiresPermissions("fishing:stats:list")
    @GetMapping("/overview")
    public AjaxResult getOverview()
    {
        Map<String, Object> overview = fishingTechniqueStatsService.getStatsOverview();
        return success(overview);
    }

    /**
     * 获取文章阅读趋势
     */
    @RequiresPermissions("fishing:stats:list")
    @GetMapping("/read-trend")
    public AjaxResult getReadTrend(@RequestParam(required = false) String startDate,
                                   @RequestParam(required = false) String endDate)
    {
        Map<String, Object> trendData = fishingTechniqueStatsService.getReadTrend(startDate, endDate);
        return success(trendData);
    }

    /**
     * 获取分类统计
     */
    @RequiresPermissions("fishing:stats:list")
    @GetMapping("/category")
    public AjaxResult getCategoryStats()
    {
        Map<String, Object> categoryStats = fishingTechniqueStatsService.getCategoryStats();
        return success(categoryStats);
    }

    /**
     * 获取热门文章排行
     */
    @RequiresPermissions("fishing:stats:list")
    @GetMapping("/popular")
    public AjaxResult getPopularArticles(@RequestParam(defaultValue = "read") String type,
                                         @RequestParam(defaultValue = "10") Integer limit)
    {
        Map<String, Object> popularData = fishingTechniqueStatsService.getPopularArticles(type, limit);
        return success(popularData);
    }

    /**
     * 获取用户活跃度统计
     */
    @RequiresPermissions("fishing:stats:list")
    @GetMapping("/user-activity")
    public AjaxResult getUserActivityStats(@RequestParam(defaultValue = "7") Integer days)
    {
        Map<String, Object> activityData = fishingTechniqueStatsService.getUserActivityStats(days);
        return success(activityData);
    }

    /**
     * 获取评论统计
     */
    @RequiresPermissions("fishing:stats:list")
    @GetMapping("/comment")
    public AjaxResult getCommentStats(@RequestParam(required = false) String startDate,
                                      @RequestParam(required = false) String endDate)
    {
        Map<String, Object> commentStats = fishingTechniqueStatsService.getCommentStats(startDate, endDate);
        return success(commentStats);
    }
}